Home:ALL Converter>Error while resolving instance for class Koin

Error while resolving instance for class Koin

Ask Time:2018-11-11T20:05:02         Author:Константин Щерба

Json Formatter

Help solve the problem!(((I have 3 modules for DI. There is a retrofit object in natworkModule, all viewModels in viewModelModule, and all requests to the server in respositoryModule. I did everything according to the documentation, but I cannot find this error in Google. Thank you in advance!!! Sorry for my english!)

class App : Application(){

    override fun onCreate() {
        super.onCreate()
        startKoin(this, listOf(natworkModule, viewModelModule,repositoryModule))
       }
    }


var natworkModule = module {

  single { createOkHttpClient() }
  single { createApiService<ApiService>(get () ,getProperty(SERVER_URL)) 

  }

}


const val SERVER_URL = "https://api.github.com/"

fun createOkHttpClient() : OkHttpClient{
   val httpLoggingInterceptor = HttpLoggingInterceptor()
   httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC
   return OkHttpClient.Builder()
        .connectTimeout(60L, TimeUnit.SECONDS)
        .readTimeout(60L, TimeUnit.SECONDS)
        .addInterceptor(httpLoggingInterceptor).build()
   }

 inline fun <reified T> createApiService(okHttpClient: OkHttpClient,  url: String): T {
   val retrofit = Retrofit.Builder()
        .baseUrl(url)
        .client(okHttpClient)
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(LiveDataCallAdapterFactory()).build()
   return retrofit.create(T::class.java)
 }

var repositoryModule = module {
    factory<TestRepository> {
        TestRepositoryImpl(get())
    }

}

var viewModelModule = module {
    viewModel {
        TestViewModel(get())
    }
}

Author:Константин Щерба,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53248547/error-while-resolving-instance-for-class-koin
yy